import React from 'react';
import { message } from 'antd';
import CommonList from '../../../components/CommonLists/list';
import Modal from '../../../components/Modal';
import services from '../../../services/api';
import { Button } from 'antd';

class OuterList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'outerList';
    this.editButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.edit.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          编辑
        </Button>
      );
    };
    this.mapButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.map.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          映射
        </Button>
      );
    };
    this.delButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.delete.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}>
          删除
        </Button>
      );
    };
    this.btnGroup = [this.editButton, this.mapButton, this.delButton];
  }

  delete({ third_list_id }) {
    Modal.open({
      title: '',
      width: '360px',
      isConfirm: true,
      content: <p>该数据接口下的映射会一并删除,确认删除么?</p>,
      isOkBtn: true,
      isCancelBtn: true,
      ok: () => {
        services[this.api].delete({ third_list_id }).then((data) => {
          if (data.code === 0) {
            message.success(data.msg);
            this.props.queryList();
            Modal.close();
          } else {
            message.error(data.msg);
          }
        });
      },
      cancel: () => {
        Modal.close();
      },
    });
  }

  refreshTableFilter = (params) => {
    this.props.refreshTableFilter && this.props.refreshTableFilter(params);
  };
}

export default OuterList;
